namespace CRMG.Container.Source.DL
{
    using CRMG.Container.Source.BO;
    using CRMG.Container.Source.Helper;
    using CRMG.Container.Source.QO;
    using Guru.Framework.BaseDal;
    using Guru.Framework.Util;
    using System;
    using System.Collections;
    using System.Data;

    public class StudentDL : BaseDL
    {

        public StudentDL()
        {
        }

        internal bool IsStudentExist(string firstname, string lastname)
        {
            try
            {
                Hashtable h = new Hashtable();
                h.Add("@FirstName", firstname);
                h.Add("@LastName", lastname);
                object retObj = base.Manager.ExecuteScalar(Crud.IsStudentExist(), h);
                return retObj.ToInt() > 0;
            }
            catch (Exception)
            {
                throw;
            }
        }

        internal DataTable GetStudentList()
        {
            try
            {
                return Manager.GetResultSet(Crud.GetStudentList()).Tables[0];
            }
            catch (Exception)
            {
                throw;
            }
        }

        internal Student GetStudentById(int studentId)
        {
            try
            {
                Student st = new Student() { OBJID = studentId };
                DataTable dt = GetById(st);
                st = null;
                foreach (DataRow row in dt.Rows)
                {
                    st = new Student()
                    {
                        OBJID = row["OBJID"].ToInt(),
                        Address = row["Address"].ToStr(),
                        BirthDate = ConverterUtil.ConvertString2DateTime(row["BirthDate"].ToString()),
                        CompanyId = row["CompanyId"].ToInt(),
                        CreatedByUser = row["CreatedByUser"].ToInt(),
                        Department = row["Department"].ToInt(),
                        GradeId = row["GradeId"].ToInt(),
                        EMail = row["EMail"].ToString(),
                        FirstName = row["FirstName"].ToString(),
                        LastName = row["LastName"].ToString(),
                        IdentityNo = row["IdentityNo"].ToString(),
                        IsActive = row["IsActive"].ToInt(),
                        MobilePhone = row["MobilePhone"].ToString(),
                        Pass = string.Empty,
                        Phone = row["Phone"].ToString(),
                        Position = row["Position"].ToInt(),
                        School = row["School"].ToInt(),
                        UpdateTime = ConverterUtil.ConvertString2DateTime(row["UpdateTime"].ToString()),
                        UpdateUser = row["UpdateUser"].ToInt(),
                        UserCreationDate = ConverterUtil.ConvertString2DateTime(row["UserCreationDate"].ToString()),
                        UserTypeId = row["UserTypeId"].ToInt(),
                        WorkAdress = row["WorkAdress"].ToString(),
                        WorkEMail = row["WorkEMail"].ToString(),
                        WorkPhone = row["WorkPhone"].ToString(),
                        WorkState = row["WorkState"].ToInt(),
                    };
                }
                return st;
            }
            catch (Exception)
            {
                throw;
            }
        }

        internal DataTable GetAllStudents()
        {
            try
            {
                DataTable dt = base.Manager.GetResultSet(Crud.GetAllStudents()).Tables[0];
                return dt;
            }
            catch (Exception)
            {
                throw;
            }
        }

        internal DataTable GetActiveStudentList()
        {
            try
            {
                DataTable dt = base.Manager.GetResultSet(Crud.GetActiveStudentList()).Tables[0];
                return dt;
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }

        internal DataTable GetDetailsOfStudent(int studentId)
        {
            try
            {
                Hashtable h = new Hashtable();
                h.Add("@StudentId", studentId);
                return base.Manager.GetResultSet(Crud.GetDetailsOfStudent(), h).Tables[0];
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}

